<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>信件详情</title>
    <%@ include file="inc/css.jsp" %>
</head>
<style>
    .paddingTop {
        padding-top: 6.5px;
    }
</style>

<body>

<div id="posts" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">信件列表</h1>
                <h4 style="margin-left: 10px;" id="showH">——查看信件</h4>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <input type="hidden" id="commentSourceId" value="${letter.id}"/>
                        <input type="hidden" id="commentType" value="0"/>

                        <form class="form-horizontal nice-validator n-default" role="form" novalidate="novalidate">
                            <c:if test="${null != letter.user}">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">用户头像:</label>

                                    <div class="col-sm-4" style="padding-top: 6.5px;">
                                        <img src="${letter.user.avatar}" height="120px" width="120px"/>
                                    </div>
                                </div>
                            </c:if>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户名称:</label>

                                <div class="col-sm-4" style="padding-top: 6.5px;">
                                    <c:if test="${null != letter.user}">
                                        ${letter.user.nickName}
                                    </c:if>
                                    <c:if test="${null == letter.user}">
                                        管理员
                                    </c:if>
                                </div>
                            </div>

                            <c:if test="${null != letter.user.region}">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">用户所在地:</label>

                                    <div class="col-sm-4 paddingTop">
                                            ${letter.user.region.city.province.name}${letter.user.region.city.name}
                                    </div>
                                </div>
                            </c:if>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">发送时间:</label>

                                <div class="col-sm-4 paddingTop">
                                    ${createTime}
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">寄信方式:</label>

                                <div class="col-sm-8 paddingTop">
                                    <c:if test="${letter.type == 1}">系统</c:if>
                                    <c:if test="${letter.type == 2}">陌生人</c:if>
                                    <c:if test="${letter.type == 3}">熟人</c:if>
                                </div>
                            </div>

                            <c:if test="${letter.type == 2}">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">偷看金额:</label>

                                    <div class="col-sm-8 paddingTop">
                                            ${letter.openMoney}元
                                    </div>
                                </div>
                            </c:if>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">寄信人信息:</label>

                                <div class="col-sm-8 paddingTop">
                                    姓名：${letter.userName}<br/>
                                    电话：${letter.mobile}<br/>
                                    地址：${letter.address}
                                </div>
                            </div>

                            <c:if test="${letter.type == 3}">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">收信人信息:</label>

                                    <div class="col-sm-8 paddingTop">
                                        姓名：${letter.toUserName}<br/>
                                        电话：${letter.toMobile}<br/>
                                        地址：${letter.toAddress}<br/>
                                        快递公司：${letterAcceptInfo.expressName}<br/>
                                        快递单号：${letterAcceptInfo.expressNum}<br/>
                                        <c:if test="${null == letterAcceptInfo || null == letterAcceptInfo.expressName || '' == letterAcceptInfo.expressName}">
                                            <a href="javascript:void(0)" onclick="_letterInfo.fn.editExpressInfo(${letterAcceptInfo.id})" type="button" class="btn btn-primary btn-sm">编辑物流信息</a>
                                        </c:if>
                                    </div>
                                </div>
                            </c:if>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">信件内容:</label>

                                <div class="col-sm-8 paddingTop">
                                    ${letter.content}
                                </div>
                            </div>

                            <c:if test="${null != stamp || null != paper || null != mailer}">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">使用物品:</label>

                                    <div class="col-sm-8 paddingTop">
                                        <c:if test="${null != stamp}">
                                            <div style="float: left;margin-right: 9%;">
                                                <img src="${stamp.cover}" style="margin-bottom: 10px;border: 1px dashed #2e6da4" height="200px" width="200px"><br/>
                                                <span>${stamp.name}</span>
                                                <span style="margin-left: 12px;">￥${stamp.money}</span>
                                                <span style="margin-left: 12px;">${stamp.num}</span><br/>
                                                <span>大头贴</span>
                                            </div>
                                        </c:if>
                                        <c:if test="${null != paper}">
                                            <div style="float: left;margin-right: 9%;">
                                                <img src="${paper.cover}" style="margin-bottom: 10px;border: 1px dashed #2e6da4" height="200px" width="200px"><br/>
                                                <span>${paper.name}</span>
                                                <span style="margin-left: 12px;">￥${paper.money}</span>
                                                <span style="margin-left: 12px;">${paper.num}</span><br/>
                                                <span>纸先生</span>
                                            </div>
                                        </c:if>
                                        <c:if test="${null != mailer}">
                                            <div style="float: left;">
                                                <img src="${mailer.cover}" style="margin-bottom: 10px;border: 1px dashed #2e6da4" height="200px" width="200px"><br/>
                                                <span>${mailer.name}</span>
                                                <span style="margin-left: 12px;">￥${mailer.money}</span>
                                                <span style="margin-left: 12px;">${mailer.num}</span><br/>
                                                <span>纸的恋人</span>
                                            </div>
                                        </c:if>
                                    </div>
                                </div>
                            </c:if>

                            <div class="form-group">
                                <div class="col-sm-12" style="text-align: center">
                                    <c:if test="${letter.type == 3 && letter.printStatus == 0}">
                                        <a href="javascript:void(0)" onclick="_letterInfo.fn.modifyPrintStatus(${letter.id},this)" type="button" class="btn btn-success">标记为已打印</a>
                                    </c:if>
                                    <a href="backend/letter/index" type="button" class="btn btn-primary">返回列表</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.panel -->
            </div>
        </div>

        <c:if test="${letter.type == 2}">
            <jsp:include page="评论列表.jsp"/>
        </c:if>

    </div>
    <!-- /#page-wrapper -->

    <!-- Modal -->
    <div class="modal fade" id="expressModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">物流信息</h4>
                </div>
                <div class="modal-body">
                    <form id="expressForm" method="post" action="backend/letter/accept/save" class="form-horizontal nice-validator n-default" role="form" novalidate="novalidate">
                        <input type="hidden" name="letterAcceptId" id="tempLetterAcceptId"/>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">快递公司:</label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="expressName" name="expressName" maxlength="20" placeholder="请输入快递公司"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">快递单号:</label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="expressNum" name="expressNum" maxlength="20" placeholder="请输入快递单号"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" onclick="_letterInfo.fn.subInfo()" class="btn btn-primary">确定</button>
                </div>
            </div>
        </div>
    </div>

</div>
<!-- /#wrapper -->

<%@ include file="inc/footer.jsp" %>

</body>

<script type="text/javascript">
    var _letterInfo = {
        v: {
            id: "_letterInfo",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {

            },
            editExpressInfo: function (id) {
                $('#tempLetterAcceptId').val(id);
                $('#expressModal').modal('show');
            },
            subInfo: function () {
                var flag = true;
                var expressName = $('#expressName').val();
                var expressNum = $('#expressNum').val();

                if (null == expressName || expressName == '') {
                    $leoman.notify('快递公司名称不能为空', "error");
                    flag = false;
                    return;
                }

                if (null == expressNum || expressNum == '') {
                    $leoman.notify('快递单号不能为空', "error");
                    flag = false;
                    return;
                }

                // 所有的验证通过后，执行新增操作
                if (flag) {
                    $("#expressForm").ajaxSubmit({
                        url: _basePath + "backend/letter/accept/save",
                        dataType: "json",
                        success: function (data) {
                            if (data == 1) {
                                $leoman.notify("操作成功", "success");
                            } else {
                                $leoman.notify("操作失败", "error");
                            }
                        }
                    });
                }
            },
            modifyPrintStatus: function (id, self) {
                $.ajax({
                    url: _basePath + "backend/letter/modifyPrintStatus",
                    dataType: "json",
                    data: {
                        id: id,
                        type: 1
                    },
                    success: function (data) {
                        if (data == 1) {
                            $leoman.notify("操作成功", "success");
                            $(self).remove();
                        } else {
                            $leoman.notify("操作失败", "error");
                        }
                    }
                });
            }
        }
    };

    $(document).ready(function () {
        _letterInfo.fn.init();
    });

</script>

</html>